package com.datastory.report.dto;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: hshe
 * @Date: 19-1-23 下午5:03
 */
public class FileView implements Serializable {
    private String name;
    private Date time;
    private long size;
    private String type;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }


    @Override
    public String toString() {
        return
                "name='" + name + '\'' +
                        ", time=" + time +
                        ", size=" + size +
                        ", type='" + type + '\'';
    }

    public String getLineData(String path) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

//        String s = "<tr><td><img src=\"/statics/images/folder.gif\" alt=\"[DIR]\"> <a href=\"/file/5i5j\">5i5j</a></td><td>2019-2-14 20:2:22</td><td>-</td></tr>";
        String s = "<tr><td>%s</td><td><a href='%s/%s'>%s</a></td><td>%s</td><td>%s</td></tr>";


        return String.format(s, this.type, "/".equalsIgnoreCase(path) ? "" : path, "/".equalsIgnoreCase(this.name) ? "" : this.name, this.name, this.size, sdf.format(this.time));
    }
}
